#include <stdio.h>

void main(){
	int i[10];
	int *p1=i,*p2=&i[9];
	scanf("%d",p1);
	do {
		scanf("%d",++p1);
	}while (p1<p2);
	p1=i;
	int *p=i,*pmax=i,*pmin=i;
	while (1){
		pmax = *pmax>*p?pmax:p;
		pmin = *pmin<*p?pmin:p;
		if (p==p2){
			break;
		}
		p++; 
	}
	int a=*p1,b=*p2;
	*p1=*pmin;
	*p2=*pmax;
	*pmin=a;
	*pmax=b;
	p=i;
	while (1){
		printf("%d ",*p);
		if (p==p2){
			break;
		}
		p++; 
	}
}
